{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# InspectDR: Basic `display` Tests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "using InspectDR\n",
    "\n",
    "#Reset list of displays for demo purposes (in case GtkDisplay is currently active)\n",
    "function resetdisplays()\n",
    "    dfltdisp = Base.Multimedia.displays[end]\n",
    "    if typeof(dfltdisp) <: InspectDR.GtkDisplay\n",
    "        pop!(Base.Multimedia.displays)\n",
    "    end\n",
    "    nothing\n",
    "end\n",
    "\n",
    "include(\"BodePlots.jl\") #Defines BodePlots.* utilities.\n",
    "plot = BodePlots.new()\n",
    "    fmin = 1e6; fmax = 10e9; G0 = 20\n",
    "    fzero = Inf; fpole1 = 50e6; fpole2 = 10e9\n",
    "BodePlots.update(plot, fmin, fmax, G0, fzero, fpole1, fpole2) #Generate some data\n",
    "println(\"\\\"plot\\\" defined.\")\n",
    "\n",
    "nothing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test inline SVG plots\n",
    "**NOTE:** SVG outputs do not render well in notebooks for some reason..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Jupyter typically requests inline graphics as SVG first.\n",
    "#Allowing MIME\"image/svg+xml\" renderings therefore produces SVG outputs:\n",
    "InspectDR.defaults.rendersvg = true\n",
    "\n",
    "resetdisplays() #Just in case\n",
    "plot #Implicit call to \"optimal\" \"show(..,::MIME,...)\" function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test inline PNG plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#When MIME\"image/svg+xml\" is disabled, Jupyter eventually requests PNG inline graphics:\n",
    "InspectDR.defaults.rendersvg = false\n",
    "\n",
    "resetdisplays() #Just in case\n",
    "display(plot) #Explicit call to display plot\n",
    "nothing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test InspectDR Gtk \"Display\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "resetdisplays() #Just in case\n",
    "pushdisplay(InspectDR.GtkDisplay()) #Make \"GtkDisplay\" highest priority\n",
    "display(plot) #This time InspectDR.GtkDisplay() is on top of display stack\n",
    "nothing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Now test display() with explicit GtkDisplay<:Display object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "resetdisplays()\n",
    "display(Base.Multimedia.displays) #GtkDisplay should not longer be on display stack\n",
    "display(InspectDR.GtkDisplay(), plot) #Explicit call to use Gtk \"display\"\n",
    "nothing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Save plot to .svg file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "InspectDR.write_svg(\"plotsave.svg\", plot) #High-quality output!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Demo complete!"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Julia 0.6.0",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
